Skip to content

tools execution wrapper unmarshal fix#21

Merged
x2d7 merged 3 commits intodevfrom
20-wrapper-unmarshal-fix
Feb 19, 2026
Merged

tools execution wrapper unmarshal fix#21
x2d7 merged 3 commits intodevfrom
20-wrapper-unmarshal-fix

Conversation

@x2d7
Copy link
Copy Markdown
Owner

@x2d7 x2d7 commented Feb 19, 2026

Summary

This PR fixes JSON unmarshaling for primitive input types in tool execution wrappers. Previously, NewTool created a correctly typed inputType via ensureInputStructType[T](), but the execution wrapper always unmarshaled into T directly — causing failures when T is a primitive like string, int, bool, or float64.

Unmarshaling now uses reflection to construct the appropriate container, ensuring primitives are handled correctly alongside struct types.

The changes affect connect/tools and corresponding tests.


Changes

1. Tool execution wrapper fix

wrapper := func(input string) (string, error) {
        // Previously: always unmarshaled into T directly
        // Now: uses reflection to build the correct container
		ptr := reflect.New(inputType)
		if err := json.Unmarshal([]byte(input), ptr.Interface()); err != nil {
			return "", fmt.Errorf("unmarshal into %v: %w", inputType, err)
		}
		return f(extract(ptr.Elem()))
	}

This ensures:

  • Primitive types (string, int, bool, float64 etc.) are unmarshaled correctly.
  • Struct types continue to work as before.
  • The inputType computed by ensureInputStructType[T]() is actually used during execution.

Tests

connect/tools

All TestNewTool_* tests were updated to include direct Execute() calls, verifying end-to-end unmarshaling behavior in addition to tool construction.

Fixed

  • TestNewTool_PrimitiveWithMapPrimitive — corrected field name to scores.

134/134 tests passing

@x2d7 x2d7 merged commit bf9de6f into dev Feb 19, 2026
1 check passed
@x2d7 x2d7 deleted the 20-wrapper-unmarshal-fix branch February 19, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant